package thu.sorit.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.util.Log;

public class WifiListener extends BroadcastReceiver {

	private SoritService service;
	
	public WifiListener(SoritService service) {
		this.service = service;
	}
	
	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager cm =
		        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
		if (activeNetwork != null) {
			if (activeNetwork.isConnected() && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
				service.notifyNetwork(true);
			} else {
				service.notifyNetwork(false);
			}
		}
	}

}
